package zuoye_3_10;

import java.util.Arrays;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Set;
import java.util.stream.Stream;

//5. hashmap去重  
//	合并 输出数组两个数组中都有元素则去除
//	[1,2,3]
//	[3,4,5,2]
//	得到[1,4,5]
public class Zuoye_5 {
	public static void main(String[] args) {
		Integer[] arr1 = {1, 2, 3};
        Integer[] arr2 = {3, 4, 5, 2};
        System.out.println(Arrays.toString(change1(arr1,arr2)));
	}

	private static Object[] change(int[] arr1, Integer[] arr2) {
		// TODO Auto-generated method stub
		 HashMap<Integer, Integer> map = new HashMap<>();
	        for (int num : arr1) {
	            map.put(num, 1);
	        }
	        for (int num : arr2) {
	            if (map.containsKey(num)) {
	                map.remove(num);
	            } else {
	                map.put(num, 1);
	            }
	        }
	        return map.keySet().toArray();
	}
	//改
	 private static Object[] change1(Integer[] arr1, Integer[] arr2) {
	        Set<Integer> set = new HashSet<>();
	        Stream.concat(Arrays.stream(arr1), Arrays.stream(arr2))
	            .forEach(num -> {
	                if (set.contains(num)) {
	                    set.remove(num);
	                } else {
	                    set.add(num);
	                }
	            });
	        return set.toArray();
	    }
}
